package com.example.demo;

import com.example.demo.repository.entity.UserEntity;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

import javax.annotation.PostConstruct;

@EnableJpaRepositories(basePackages = {"com.example.demo.repository.jpa"})
@EntityScan(basePackages = {"com.example.demo.repository.entity"})
@SpringBootApplication
public class DynamicHibernateApplication {

    public static void main(String[] args) {
        SpringApplication.run(DynamicHibernateApplication.class, args);
    }

    @Autowired
    private UserService userService;

    @PostConstruct
    public void doAfterStarted(){
        UserEntity user1 = userService.selectFromPrimary();
        UserEntity user2 = userService.selectFromSecond();

        System.out.println(user1);
        System.out.println(user2);
    }
}
